package org.iku.crawl.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.heydr.entity.Info;
import org.heydr.entity.Site;
import org.heydr.entity.Url;
import org.iku.entity.Actress;
import org.iku.entity.Category;
import org.iku.entity.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ResourceDAO {

	@Autowired
	private SqlSession sqlSession;
	
	public List<Site> availableSiteInfos(){
		return sqlSession.selectList("ResourceMapper.availableSiteInfos");
	}
	
	public List<Url> availableUrls(int size){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("size", size);
		return sqlSession.selectList("ResourceMapper.availableUrls",params);
	}
	
	public void storeUrl(Url url){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("url", url);
		sqlSession.insert("ResourceMapper.storeUrl",params);
	}
	
	public void storeItemInfo(Info info){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("info", info);
		sqlSession.insert("ResourceMapper.storeItemInfo",params);
	}
	
	public void updateUrl(Url url){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("url", url);
		sqlSession.update("ResourceMapper.updateUrl",params);
	}
	
	public int addCategory(Category category){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("category", category);
		return sqlSession.insert("ResourceMapper.addCategory",params);
	}
	
	public int addActress(Actress actress){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("actress", actress);
		return sqlSession.insert("ResourceMapper.addActress",params);
	}
	
	public int addItem(Item item){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("item", item);
		return sqlSession.insert("ResourceMapper.addItem",params);
	}
}
